<template>
  <div>
    <div class="recommend">
      <div class="recommend-top"></div>
      <!-- 轮播图 -->
      <div class="recommend-header">
        <div class="rotation-chart">
          <van-swipe class="ul" :autoplay="3000">
            <van-swipe-item
              class="li"
              v-for="(item, index) in banners"
              :key="index"
            >
              <img v-lazy="item.i" />
            </van-swipe-item>
          </van-swipe>
        </div>
      </div>
      <!-- 内容 -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getHomeRecommendedFun()"
        style="padding-bottom: 60px"
      >
        <!-- 内容 -->
        <div
          class="recommend-content"
          v-for="(item, index) in recommendList"
          :key="index"
        >
          <div class="content-header">
            <div class="header-img">
              <img :src="item.a.p" alt="" />
            </div>
            <div class="header-user">
              <div class="username">
                <h3>{{ item.a.n }}</h3>
                <span>LV.{{ item.a.lvl }}</span>
              </div>
            </div>
            <div class="header-follow">
              <span>关注</span>
            </div>
          </div>
          <div class="content-img" @click="jump(item.id)">
            <img :src="item.img" alt="" />
            <div></div>
          </div>
          <div class="content-footer">
            <div class="footer-top">
              <ul class="top-left" v-if="item.collect_users">
                <li v-for="(k, i) in item.collect_users" :key="i">
                  <img :src="k.p" alt="" />
                </li>
              </ul>
              <div class="top-center">
                <span>{{ item.collect_count_text }}</span>
              </div>
              <div class="top-right">
                <i class="iconfont icon-shoucang"></i>
              </div>
            </div>
            <div class="footer-center">
              <span> {{ item.n }} </span>
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { getHomeRecommended } from "../../api/home/recommend";
export default {
  name: "recommend",
  data() {
    return {
      loading: false,
      finished: false,
      banners: [],
      recommendList: [],
      id:"",
    };
  },
  methods: {
    //获取推荐随机
    getHomeRecommendedFun() {
      getHomeRecommended({ offset: 20, limit: 20 }).then((data) => {
        // console.log("推荐列表数据", data.result);

        let banner = data.result.banner;
        this.banners = banner;
        // console.log("轮播图数据",this.banner);

        let recommend = data.result.list;
        recommend.forEach((value) => {
          if (value.type == 1 && value.r.collect_count_text) {
            this.recommendList.push(value.r);
          }
        });

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.recommendList.length >= 20) {
          this.finished = true;
        }
      });
    },
    //跳转详情页
    jump(id) {
      this.id = id;
      this.$router.push({
        name: "details",
        params: {
          id: this.id,
        },
      });
    },
  },
  created() {
    // this.getHomeRecommendedFun();
  },
};
</script>

<style lang="less">
.recommend {
  .recommend-top {
    width: 100%;
    height: 105px;
  }
  .recommend-header {
    width: 100%;
    height: 110px;
    // border-bottom: 2px solid #f2f2f2;
    .rotation-chart {
      width: 100%;
      overflow: hidden;
      .ul {
        .li {
          width: 375px;
          height: 110px;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }
  .recommend-content {
    margin-top: 20px;
    padding-bottom: 10px;
    .content-header {
      margin: 15px 10px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .header-img {
        width: 35px;
        height: 35px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .header-user {
        width: 61%;
        margin-left: 10px;
        .username {
          font-weight: bold;
          display: flex;
          align-items: center;
          h3 {
            font-size: 14px;
            font-weight: bold;
            color: #000;
          }
          span {
            font-size: 10px;
            color: #c48f23;
            margin-left: 10px;
          }
        }
        .user-information {
          span {
            font-size: 12px;
            color: #868686;
          }
        }
      }
      .header-follow {
        margin-right: 5px;
        span {
          width: 70px;
          height: 30px;
          font-size: 12px;
          font-weight: bold;
          color: #000;
          background-color: #fec538;
          border: 1px solid #fec538;
          border-radius: 50px;
          padding: 5px 20px;
        }
      }
    }
    .content-img {
      width: 100%;
      background-color: #e0e0e0;
      margin-bottom: 12px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .content-footer {
      margin: 15px 12px 0;
      .footer-top {
        margin: 5px 0px;
        display: flex;
        .top-left {
          width: 20%;
          height: 25px;
          position: relative;
          li:nth-child(1) {
            position: absolute;
            top: 0;
            left: 0;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(2) {
            position: absolute;
            top: 0;
            left: 16px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(3) {
            position: absolute;
            top: 0;
            left: 32px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(4) {
            position: absolute;
            top: 0;
            left: 48px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
        }
        .top-center {
          width: 38.6%;
          height: 25px;
          line-height: 25px;
          margin-left: 10px;
          span {
            font-size: 14px;
            // font-weight: bold;
            color: #000;
          }
        }
        .top-right {
          width: 32%;
          height: 25px;
          line-height: 25px;
          margin-left: 15px;
          display: flex;
          justify-content: flex-end;
          i {
            font-size: 25px;
          }
        }
      }
      .footer-center {
        width: 93%;
        // height: auto;
        margin-top: 10px;
        span {
          width: 335px;
          line-height: 25px;
          display: block;
          font-size: 14px;
          font-weight: bold;
          color: #000;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
      }
    }
  }
}
</style>